<?php
namespace app\admin\controller;

use app\admin\logic\BranchLogic;
use app\admin\logic\RoleLogic;
use app\admin\logic\UserLogic;
use think\Request;

class User extends Base{
	private $userLogic;
	public function __construct( Request $request = null ) {
		parent::__construct( $request );
		$this->userLogic=new UserLogic();
	}

	// 列表页
	public function index(){
		$users=$this->userLogic->query('');
		$this->assign('list',$users);
		return $this->fetch();
	}

	//新增用户页面
	public function add($id=0){
		$user=null;
		if($id>0){
			$user=$this->userLogic->findOne($id);
		}
		$roles=(new RoleLogic())->query();
        $branch = (new BranchLogic())->findAll();

		$this->assign('roles',$roles);
		$this->assign('user',$user);
        $this->assign('branch',$branch);

		return $this->fetch();
	}

	//保存数据
	public function doAdd($param=''){
		$userArr=json_decode($param,true);
        $userArr["enable"] = true;
		$res=$this->userLogic->addUser($userArr);
		return $res;
	}

	//删除数据
	public function del($id=0){
		$res=$this->userLogic->del($id);
		return $res;
	}

	public function modifyPwd(){
		$id=session('id');
		$user=$this->userLogic->findOne($id);
		$this->assign('user',$user);
		return $this->fetch();
	}

	public function chkPwd($pwd=''){
		return $this->userLogic->chkPwd($pwd);
	}

	public function doModifyPwd($param=''){
		return $this->userLogic->doModifyPwd($param);
	}
}


